graph = {
    'A': ['B', 'C'],
    'B': ['A', 'D', 'E'],
    'C': ['A', 'F'],
    'D': ['B'],
    'E': ['B', 'F'],
    'F': ['C', 'E']
}

def dfs(graph,start,visited=None):
    if visited is None:
        visited = set()
    visited.add(start)
    print(start,end=' ')
    for next_node in graph[start]:
        if next_node not in visited:
            dfs(graph,next_node,visited)
from collections import deque
def bfs(graph,start):
    visited = set()
    queue = deque([start])
    while queue:
        vertex = queue.popleft()
        if vertex not in visited:
            visited.add(vertex)
            print(vertex,end=' ')
            queue.extend(set(graph[vertex])- visited)
    return visited

dfs(graph,'A')
bfs(graph,'A')